<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ncduc
 * Date: 7/2/13
 * Time: 11:50 AM
 * To change this template use File | Settings | File Templates.
 */
include_once("../libs/setup.php");
include_once("../libs/helper.php");
session_start();

if (!check_user_session()) {
    header("Location: ../signin.php");
    return;
}
if(empty($_REQUEST['url']))
{
    page_not_found();
    return;
}
$userId = $_SESSION['ma_user'];
$upload_folder = $_SERVER['DOCUMENT_ROOT'] . "/oms/uploads/".$userId;
$temp_folder = $_SERVER['DOCUMENT_ROOT'] . "/oms/downloads";

$url = $_REQUEST['url'];
if(file_exists($upload_folder . "/" . $url))
{
    $src_file = $upload_folder . "/" . $url;
    $des_file = $temp_folder."/".$url;
    copy($src_file,$des_file);
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($des_file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($des_file));
    readfile($des_file );
//remove file after download  
unlink($des_file);
}